/* ========================================== */
/*                                            */
/* Assorted bargraph and other output effects */
/*                                            */
/* ========================================== */

// Function to draw a proportional bargraph which always
// fits into the eight LED's no matter the span.
// That is provided you don't go over the span.
//
char BarGraph(long long int position, long long int span)
{
	signed long long int
		partial,
		eighth;

	char result=0;

	// Calculate how much one bit is worth
	//
	eighth = span / 8;
	partial = position;

	// set the required amount of bit's.
	//
	while(partial > 0)
	{
		partial -= eighth;
		result = result << 1;
		result |= 1;

	}

	return result;
}


// This function places a single light on in the
// position referenced by bar_posn.
//
// It is used to indicate which program is presently
// active or being selected
//
void BarPoint(char bar_posn)
{
	char lampsig=1;
	lampsig = lampsig << bar_posn;

	ShiftOut( lampsig);
}


// This function indicates the mode of operation by
// flashing the lights pointed to by Mode.
//
void FlashMode(ModeTypes mode)
{
	int i;

	const char lights[3]=
		{
			0b11000011,
			0b01100110,
			0b00011000
		};

	for(i=0; i < 8; i++)
	{
		ShiftOut(lights[mode]);
		delay_ms(75);
		ShiftOut(0);
		delay_ms(75);
	}
}
